package com.hannesdorfmann.mosby3.mvi.integrationtest.slice;

import com.hannesdorfmann.mosby3.mvi.integrationtest.ResourceTable;
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fraction.SimpleFractionAbility;
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fraction.SimpleMviLifecycleFraction;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

public class SimpleFractionAbilitySlice extends AbilitySlice {

    private static final String TAG = "Test-Fragment";
    private static volatile SimpleFractionAbilitySlice currentInstance;


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        currentInstance = getInstance();
        super.setUIContent(ResourceTable.Layout_ability_lifecycle);

        SimpleMviLifecycleFraction f = new SimpleMviLifecycleFraction();

        ((SimpleFractionAbility) getAbility()).getFractionManager()
                .startFractionScheduler()
                .replace(ResourceTable.Id_container, f)
                .pushIntoStack(TAG)
                .submit();
    }

    public static SimpleFractionAbilitySlice getInstance(){
        if(SimpleFractionAbilitySlice.currentInstance == null){
            SimpleFractionAbilitySlice.currentInstance = new SimpleFractionAbilitySlice();
        }
        return  SimpleFractionAbilitySlice.currentInstance;
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
